import { ITimer } from "../../api/timer/ITimer";
import { TimerUtils } from "../../api/timer/TimerUtils";
import { CDLotteryBase } from "../excel/CDLotteryBase";
import { Player } from "../struct/Player";



/**最大连抽次数 */
export const MAX_LOTTERY_TIMES = 5;




/**
 * 数据-抽奖
 */
export abstract class SDLottery {


    /**
     * 获取更新倒计时
     * @param player 
     * @param now 
     */
    public static getUpdateCountDown(
        player: Player,
        now = ITimer.getServerTime()
    ): number {
        const nt = TimerUtils.getDayZeroTime(now);
        const delay = now - nt;
        return delay <= 5 ? 5 : delay;
    }



    /**
     * 获取抽奖消耗
     * @param player 
     * @param baseConfig 
     * @param times
     */
    public static getCostItemNum(
        player: Player,
        baseConfig: number | CDLotteryBase,
        times: number
    ): number {

        if (!(baseConfig instanceof CDLotteryBase)) {
            baseConfig = CDLotteryBase.getData(baseConfig);
        }

        if (baseConfig) {
            const useTimes = player.lottery.getLotteryTimesDaily(baseConfig.id);
            const need = Math.min(times, (useTimes + times) - baseConfig.freeTimes);
            if (need > 0) {
                const cost = need * baseConfig.costNum;
                return cost;
            }
        }

        return 0;
    }



}
